import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by IFT8
 * on 2015/7/16.
 */
@WebServlet(name = "TestServlet", value = "/test.s")
public class TestServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String str = "";
        String[] strs = new String[5];
        System.out.println(str.getClass().getName());
        System.out.println(strs.getClass().getName());
        String dateStr = request.getParameter("birthday");
        DateFormat[] dateFormats = {
                new SimpleDateFormat("yyyy-MM-dd"),
                new SimpleDateFormat("yyyy/MM/dd"),
                new SimpleDateFormat("yyyy.MM.dd")
        };
        //格式到日期 yyyy-MM-dd( yyyy/MM/dd yyyy.MM.dd)----->Date
        ParseException e = null;
        for (DateFormat dateFormat : dateFormats)
            try {
                Date date = dateFormat.parse(dateStr);
                System.out.println(date);
                return;
            } catch (ParseException ex) {
                e = ex;
                continue;
            }
        throw new RuntimeException(e);
    }
}
